package org.benjamin.lending.commons;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.jdbc.core.JdbcTemplate;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * Created by xywen on 2017/6/22.
 */
public class CreateTable {

    private final Logger logger = LogManager.getLogger();

    @Autowired
    private JdbcTemplate jdbcTemplate;

    public void ex() throws IOException {
        try{
            String tablesList = this.jdbcTemplate.queryForObject("SHOW TABLES LIKE 'tab_borrow_tender'",String.class);
            List queryForList = this.jdbcTemplate.queryForList("SHOW COLUMNS FROM tab_borrow_tender");
            logger.info(tablesList);
            if(tablesList.isEmpty() && queryForList.size() != 8){
                this.jdbcTemplate.execute("CREATE TABLE tab_borrow_tender(" +
                        "id INT PRIMARY KEY AUTO_INCREMENT," +
                        "auto BIT NOT NULL DEFAULT 0," +
                        "bid INT NOT NULL ," +
                        "uid INT NOT NULL ," +
                        "investor_capital DECIMAL(19,2) NOT NULL ," +
                        "investor_interest DECIMAL(19,2) NOT NULL" +
                        " )");
            }
        }catch (Exception e){
            logger.error(e.getMessage(),e);
        }
    }
}
